using System;
using System.Collections;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;
using PHSRAG.Insight21.CDS;
using PHSRAG.Insight21.Common.Pages;
using PHSRAG.Insight21.FormsManagement;
using PHSRAG.Insight21.Policy;
using PHSRAG.Utility;
using Forms = PHSRAG.Insight21.FormsManagement;

namespace PHSRAG.Insight21.Humans
{
    /// <summary>
    /// Summary description for AddDeleteForms.
    /// </summary>
    public partial class AddDeleteForms : BasePage
    {
        #region Instance Variables

        private ICachePolicy applicationCachePolicy;
        private ICachePolicy cachePolicy;
        private bool confirmDelete;
        private ProtocolProcess currentProcess;
        private ProtocolVersion currentVersion;
        private Hashtable pageCache;
        private ICachePolicy pageCachePolicy;
        private Protocol protocol;
        private int protocolId;
        private ProtocolProcess protocolProcess;
        private int protocolProcessId;

        //This flag is used to decide whether or not the headers should be displayed
        //If the page is to be displayed as a popup, then the header section is made invisible
        private bool showAsPopUp;
        private int userAccessLevel;

        #endregion

        #region Constants

        private const string AddCommand = "Add";
        private const string AddImage = "../Images/b_add.gif";
        private const string AddImageGrey = "../Images/b_add_grey.gif";
        private const string AnnunciatorTitle = "The following error(s) occurred...";
        private const string DeleteCommand = "Delete";

        /// <summary>Button the user clicks when they've finished doing the work on this page. 
        /// It fires the OnDone event.</summary>
        private const string DeleteConfirmationFlag = "deleteConfirmFlag";

        private const string DeleteImage = "../Images/b_delete.gif";
        private const string DeleteImageGrey = "../Images/b_deleteongray.gif";
        private const string PageCacheKey = "addDeleteFormsPage_A6E0CA07-A3A2-499c-9C1F-D3B458BEDF43";
        private const string ProtocolAccessLevelKey = "protocolAccessLevel_CB893AA2-D07E-472b-907A-7B22FC894043";

        #endregion

        #region Properties

        /// <summary>
        /// Gets the protocol for which staffing is being reviewed or modified.  If it's not already
        /// in the cache, it loads it up based on the protocolId passed to the page, and caches the object
        /// </summary>
        private Protocol Protocol
        {
            get
            {
                string cacheKey = Protocol.ProtocolKey;
                protocol = cachePolicy.GetCachedObject(cacheKey) as Protocol;

                if ((protocol == null) || (protocolId != protocol.Id))
                {
                    protocol = new Protocol(cachePolicy);
                    protocol.Load(DataAccess.GetConnectionString(), protocolId);
                    cachePolicy.Cache(cacheKey, protocol);
                }
                return protocol;
            }
        }

        /// <summary>
        /// Gets the protocol process for which staffing is being reviewed or modified.  If it's not already
        /// in the cache, it loads it up based on the protocolProcessId passed to the page, and caches the 
        /// object
        /// </summary>
        private ProtocolProcess ProtocolProcess
        {
            get
            {
                protocolProcess = cachePolicy.GetCachedObject(ProtocolProcess.ProtocolProcessKey)
                    as ProtocolProcess;

                if ((protocolProcess == null) || (protocolProcessId != protocolProcess.Id))
                {
                    if (protocolProcessId > 0)
                    {
                        protocolProcess = ProtocolProcess.GetProtocolProcess(
                            DataAccess.GetConnectionString(), protocolProcessId, cachePolicy, null);
                        cachePolicy.Cache(ProtocolProcess.ProtocolProcessKey, protocolProcess);
                    }
                    else
                    {
                        protocolProcess = null;
                    }
                }
                return protocolProcess;
            }
        }

        #endregion

        protected void OnPageLoad(object sender, EventArgs e)
        {
            try
            {
                pageCache = pageCachePolicy.GetCachedObject(PageCacheKey) as Hashtable ?? new Hashtable();

                breadCrumb.Add(
                    "Add Delete Forms",
                    Settings.GetKeyValue("SubModuleNavigation.Humans.ProtocolProcessOverviewURL", ""),
                    Settings.GetKeyValue("BreadCrumb.DetailPageLevel", 2));


                Hashtable incomingPageHash =
                    cachePolicy.GetCachedObject(Keys.IncomingDataKey) as Hashtable;

                string formData = Request.Form[DeleteConfirmationFlag];
                confirmDelete = (formData != null && formData == "True");


                if (incomingPageHash != null)
                {
                    if (incomingPageHash.ContainsKey(Keys.ShowAsPopUp))
                    {
                        showAsPopUp = Convert.ToBoolean(incomingPageHash[Keys.ShowAsPopUp]);
                    }

                    userAccessLevel = Convert.ToInt32(incomingPageHash[Keys.ProtocolAccessKey]);
                    protocolId = Convert.ToInt32(incomingPageHash[Keys.ProtocolIdKey]);
                    protocol = new Protocol(cachePolicy);
                    protocol.Load(DataAccess.GetConnectionString(), protocolId);
                    protocol.Cache();
                    protocolProcessId = Convert.ToInt32(incomingPageHash[Keys.ProtocolProcessIdKey]);
                    protocolProcess = ProtocolProcess.GetProtocolProcess(DataAccess.GetConnectionString(), protocolProcessId, cachePolicy, null);
                    pageCache[ProtocolAccessLevelKey] = userAccessLevel;
                    pageCache[Keys.ShowAsPopUp] = showAsPopUp;
                    protocolProcess.Cache();
                }
                else
                {
                    showAsPopUp = (bool) pageCache[Keys.ShowAsPopUp];
                    userAccessLevel = (int) pageCache[ProtocolAccessLevelKey];
                }

                // get the Protocol Version from the Process
                currentProcess = (ProtocolProcess) cachePolicy.GetCachedObject(ProtocolProcess.ProtocolProcessKey);
                currentVersion = currentProcess.GetLatestProtocolVersion(true, cachePolicy);

                if (!IsPostBack)
                {
                    ArrayList gridList = PopulateGridQuestionnaireList(
                        currentVersion.GetCompleteQuestionnaireAnswerList(
                            currentVersion.QuestionnaireAnswers,
                            cachePolicy,
                            DataAccess.GetConnectionString(), header.ModuleName),
                        currentProcess.Type);

                    formsGrid.DataSource = gridList;
                    formsGrid.DataBind();
                    userAccessLevel = (int) pageCache[ProtocolAccessLevelKey];
                }

                //if page is being shown as popup, then hide the header section
                headerSection.Visible = !showAsPopUp;
            }
            catch (Exception ex)
            {
                annunciator.Message = ex.Message;
                done.Enabled = false;
                formsGrid.Enabled = false;
            }
            finally
            {
                protocolDetailHeader.ProtocolID = protocolId;
                //Set the humansubmodule Navigation links
                humansSubModNavigation.ProtocolProcess = ProtocolProcess;
                humansSubModNavigation.Protocol = Protocol;
            }
        }

        /// <summary>
        /// PopulateGridQuestionnaireList gets a complete listing of all QuestionnaireAnswers the
        /// ProtocolVersion has, PLUS any QuestionnaireVersions the user has not yet answered (the
        /// requirement script didn't add them based on their answers) AND any QuestionnaireVersions 
        /// that AllowMultiple forms of the same questionnaire to be answered (like Drugs). This method
        /// also groups the QuestionnaireANswers based on their Questionnaire Category type, ordered by
        /// the appropriate Reference attribute for it.
        /// </summary>
        /// <param name="answerList">listing of the existing QuesionnaireAnswers for the ProtocolVersion 
        /// the person is editing.</param>
        /// <param name="processType">The type of process that's being modified- if it's an initial review,
        ///	we want to hide the initial "Config Wizard" questionnaire, but if it's another type, (ex. Amendment,
        ///	then the initial form (Config Wizard) will be displayed.</param>
        /// <returns></returns>
        private ArrayList PopulateGridQuestionnaireList(ArrayList answerList, string processType)
        {
            ArrayList gridArrayList = new ArrayList();

            try
            {
                // get the Ref Codes, and add them one by one, along with any in teh Answer List.
                RefCodes refCodes = (RefCodes) applicationCachePolicy.GetCachedObject(RefCodes.CacheKey);

                ArrayList questTypes;
                if (header.ModuleName.ToLower() == "humans")
                {
                    questTypes = refCodes.GetSortedRefCodes(FormsManagement.Constants.CommonFormCategory.Domain,
                        FormsManagement.Constants.CommonFormCategory.OrderAttribute);

                    for (int i = 0, count = questTypes.Count; i < count; ++i)
                    {
                        RefCode code = (RefCode) questTypes[i];

                        if ((code.Code == FormsManagement.Constants.CommonFormCategory.InitialApplication) &&
                            (processType == Constants.ProtocolProcessType.InitialReview))
                        {
                            continue;
                        }

                        // hide intervention forms if it's not an intervention protocol
                        if ((protocol.IsInterventionStudy == 0) &&
                            (code.Attributes["Intervention"] != null) && ((string) code.Attributes["Intervention"] == "Y"))
                        {
                            continue;
                        }
                        // if the protocol is an intervention study, then hide the non-intervention forms
                        if ((protocol.IsInterventionStudy == 1) &&
                            (code.Attributes["Intervention"] != null) && ((string) code.Attributes["Intervention"] == "N"))
                        {
                            continue;
                        }

                        QuestionnaireAnswer groupCode = new QuestionnaireAnswer(cachePolicy);
                        groupCode.Name = code.Meaning;

                        // fake out the Multiple attribute for the type here, since it doesn't 
                        // apply but is needed for the binding.
                        groupCode.VersionAllowsMultiple = false;

                        gridArrayList.Add(groupCode);

                        for (int j = 0, answerCount = answerList.Count; j < answerCount; ++j)
                        {
                            QuestionnaireAnswer currAns = (QuestionnaireAnswer) answerList[j];
                            if (currAns.QuestionnaireCategory == code.Code && !currAns.MarkForDelete)
                            {
                                gridArrayList.Add(currAns);
                            }
                        }
                    }
                }
                else if (header.ModuleName.ToLower() == "animals")
                {
                    questTypes = refCodes.GetSortedRefCodes(FormsManagement.Constants.AnimalsFormCatgory.Domain,
                        FormsManagement.Constants.AnimalsFormCatgory.OrderAttribute);

                    for (int i = 0, count = questTypes.Count; i < count; ++i)
                    {
                        RefCode code = (RefCode) questTypes[i];

                        //skip all the initial process questionnaires
                        if ((code.Code == FormsManagement.Constants.AnimalsFormCatgory.InitialApplication) ||
                            (code.Code == FormsManagement.Constants.AnimalsFormCatgory.Amendment) ||
                                (code.Code == FormsManagement.Constants.AnimalsFormCatgory.AnnualReview) ||
                                    (code.Code == FormsManagement.Constants.AnimalsFormCatgory.Deficiency) ||
                                        (code.Code == FormsManagement.Constants.AnimalsFormCatgory.InitialStandardApplication) ||
                                            (code.Code == FormsManagement.Constants.AnimalsFormCatgory.InitialTissueApplication) ||
                                                (code.Code == FormsManagement.Constants.AnimalsFormCatgory.TriennialReview))
                        {
                            continue;
                        }

                        QuestionnaireAnswer groupCode = new QuestionnaireAnswer(cachePolicy);
                        groupCode.Name = code.Meaning;

                        // fake out the Multiple attribute for the type here, since it doesn't 
                        // apply but is needed for the binding.
                        groupCode.VersionAllowsMultiple = false;

                        gridArrayList.Add(groupCode);

                        for (int j = 0, answerCount = answerList.Count; j < answerCount; ++j)
                        {
                            QuestionnaireAnswer currAns = (QuestionnaireAnswer) answerList[j];

                            // skip Qualifications & Experience, Occupational Health Survey for privacy 
                            // reasons :: trackit 9170
                            if (currAns.QuestionnaireCategory == code.Code && !currAns.MarkForDelete
                                && currAns.QuestionnaireVersion.Questionnaire.Name != "Occupational Health Survey"
                                    && currAns.QuestionnaireVersion.Questionnaire.Name != "Qualifications and Experience")
                            {
                                gridArrayList.Add(currAns);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                annunciator.Message = ex.Message;
                done.Enabled = false;
                formsGrid.Enabled = false;
            }

            return gridArrayList;
        }

        /// <summary>
        /// Resets the subnavigation selected link before the breadCrumb performs a redirect.
        /// </summary>
        /// <param name="sender">Control which rasied the event.</param>
        /// <param name="e">Arguments associated with the event.</param>
        private void OnBreadCrumbNavigate(object sender, CommandEventArgs e)
        {
            try
            {
                humansSubModNavigation.Reset();
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }

        /// <summary>
        /// Resets the subnavigation selected link before the header or the breadCrumb performs a redirect.
        /// </summary>
        /// <param name="sender">Control which rasied the event.</param>
        /// <param name="e">Arguments associated with the event.</param>
        private void OnNavigate(object sender, CommandEventArgs e)
        {
            try
            {
                humansSubModNavigation.Reset();
                humansSubNavigation.Reset();
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }

        /// <summary>
        /// Constructs and caches a hashtable of data for use by the page to which nagivation leads
        /// </summary>
        private void OnHumansSubModNavigate()
        {
            try
            {
                Hashtable outgoingData = new Hashtable();
                outgoingData.Add(Keys.ProtocolAccessKey, userAccessLevel);
                outgoingData.Add(Keys.ProtocolIdKey, protocolId);
                outgoingData.Add(Keys.ProtocolProcessIdKey, protocolProcessId);
                pageCachePolicy.Cache(Keys.IncomingDataKey, outgoingData);
            }
            catch (Exception ex)
            {
                DisplayExceptionReport(ex);
            }
        }

        private void OnItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // Setup the group headers here...
                if (e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.QuestionnaireVersionId].Text == "0")
                {
                    TableCell groupHeader = e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Name];
                    groupHeader.Font.Bold = true;
                    groupHeader.BackColor = Color.Orange;
                    e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.ActionButton].Controls.RemoveAt(1);
                }
                else
                {
                    // Create one button to use throughout the logic of the function
                    ImageButton addDeleteForm = (ImageButton) e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.ActionButton].Controls[1];

                    // setup the appropriate Add/Delete button 
                    // if allows multiple
                    if (Convert.ToBoolean((e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.VersionAllowsMultiple]).Text) &&
                        currentVersion.Id == 0)
                    {
                        addDeleteForm.ImageUrl = (e.Item.ItemType == ListItemType.Item) ? AddImageGrey : AddImage;
                        addDeleteForm.Visible = true;
                        addDeleteForm.CommandName = AddCommand;
                    }
                        // allow deletion of the ones that aren't required, or add them if they're not entered yet.
                    else if (Convert.ToBoolean((e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Required]).Text) != true)
                    {
                        addDeleteForm.Visible = true;

                        if (e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Id].Text == "0")
                        {
                            addDeleteForm.ImageUrl = AddImage;
                            addDeleteForm.CommandName = AddCommand;
                        }
                        else
                        {
                            addDeleteForm.ImageUrl = DeleteImage;
                            addDeleteForm.CommandName = DeleteCommand;
                            addDeleteForm.Attributes["onclick"] = "ConfirmDelete();";
                        }
                    }
                    else
                    {
                        // else these are required ones, so you can't add or delete them, so hide the button.
                        addDeleteForm.Visible = false;
                    }
                }
            }
        }

        /// <summary>
        /// The forms grid has a button column on it, and depening on some attributes of the 
        /// QUestionnaireAnswer being bound to the grid, the button will be displayed and will fire
        /// an Add or Delete event, depending on teh Questionnaire for that row. For example,
        /// certain questionnaires cannot be deleted (meaning they're required), and others can be added once
        /// (if they're not added via the requirement script), OR they can be added multiple times (ex. Drugs).
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">the sending argument from the datagrid.</param>
        private void OnButtonClick(object source, DataGridCommandEventArgs e)
        {
            try
            {
                currentProcess = (ProtocolProcess) cachePolicy.GetCachedObject(ProtocolProcess.ProtocolProcessKey);

                if (e.CommandName == AddCommand)
                {
                    // get the QuestionnaireVersion ID from teh row, create a QuestionnaireVersion 
                    // with this ID and add it to the current Protocol Verison.
                    QuestionnaireAnswer newAnswer = currentVersion.AddNewQuestionnaireAnswer(
                        Convert.ToInt32(e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.QuestionnaireVersionId].Text),
                        cachePolicy);
                    // set a default name
                    Questionnaire q = newAnswer.QuestionnaireVersion.Questionnaire;
                    switch (q.Category)
                    {
                        case FormsManagement.Constants.CommonFormCategory.Drugs:
                            newAnswer.Name = FormsManagement.Constants.QuestionnaireAnswerDefaultNames.Drugs;
                            break;
                        case FormsManagement.Constants.CommonFormCategory.Devices:
                            newAnswer.Name = FormsManagement.Constants.QuestionnaireAnswerDefaultNames.MedicalDevices;
                            break;
                        case FormsManagement.Constants.CommonFormCategory.SpecialPop:
                            newAnswer.Name = newAnswer.VersionAllowsMultiple ? FormsManagement.Constants.QuestionnaireAnswerDefaultNames.Children : e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Name].Text;
                            break;
                        case FormsManagement.Constants.CommonFormCategory.SponsorFunding:
                            newAnswer.Name = (ProtocolProcess.Type == Constants.ProtocolProcessType.Amendment
                                || ProtocolProcess.Type == Constants.AnimalProtocolProcessType.Amendment) 
                                ? FormsManagement.Constants.QuestionnaireAnswerDefaultNames.Sponsor_AM 
                                : FormsManagement.Constants.QuestionnaireAnswerDefaultNames.Sponsor_IR;
                            break;
                        case FormsManagement.Constants.AnimalsFormCatgory.Hazardous:
                            newAnswer.Name = FormsManagement.Constants.AnimalsQuestionnaireAnswerDefaultNames.Hazardous;
                            break;
                        case FormsManagement.Constants.AnimalsFormCatgory.Procedures:
                            newAnswer.Name = newAnswer.VersionAllowsMultiple ? FormsManagement.Constants.AnimalsQuestionnaireAnswerDefaultNames.Procedures : e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Name].Text;
                            break;
                        case FormsManagement.Constants.AnimalsFormCatgory.Anesthesia:
                            newAnswer.Name = newAnswer.VersionAllowsMultiple ? FormsManagement.Constants.AnimalsQuestionnaireAnswerDefaultNames.Anesthesia : e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Name].Text;
                            break;
                        case FormsManagement.Constants.AnimalsFormCatgory.TumorProduction:
                            newAnswer.Name = FormsManagement.Constants.AnimalsQuestionnaireAnswerDefaultNames.Tumor;
                            break;
                        default:
                            newAnswer.Name = e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Name].Text;
                            break;
                    }
                    newAnswer.QuestionnaireCategory = e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.QuestionnaireCategory].Text;

                    currentProcess.LastModifiedDate = DateTime.Now;
                    currentProcess.Save(DataAccess.GetConnectionString());
                    currentVersion.Save(DataAccess.GetConnectionString());
                }
                else if (e.CommandName == DeleteCommand)
                {
                    if (confirmDelete)
                    {
                        // Get the QuestionnaireAnswerId from the grid, delete that QuesitonnaireAnswer from 
                        // the protocolVersion and delete it.
                        int deletedAnswerId = Convert.ToInt32(e.Item.Cells[(int) AddDeleteFormsGridColumnIndex.Id].Text);
                        currentVersion.DeleteQuestionnaireAnswer(deletedAnswerId);
                    }
                }

                // now recache the Protocol Version
                currentVersion.UnCache();
                currentVersion.Cache();

                // rebind the grid.
                currentVersion.QuestionnaireAnswers = null;

                ArrayList gridList = PopulateGridQuestionnaireList(
                    currentVersion.GetCompleteQuestionnaireAnswerList(
                        currentVersion.QuestionnaireAnswers,
                        cachePolicy,
                        DataAccess.GetConnectionString(), header.ModuleName)
                    , currentProcess.Type);

                formsGrid.DataSource = gridList;
                formsGrid.DataBind();
            }
            catch (Exception ex)
            {
                annunciator.Message = ex.Message;
                formsGrid.Enabled = false;
                done.Enabled = false;
            }
        }

        /// <summary>
        /// The OnDone event is fired when the "Done" button is clicked, after the 
        /// user has performed all necessary actions. This event caches required IDs and 
        /// redirects the user to the ProtocolProcessOVerview page.
        /// </summary>
        /// <param name="sender">The control which raised the event.</param>
        /// <param name="e">Arguments assocoiated with the event</param>
        private void OnDone(object sender, ImageClickEventArgs e)
        {
            try
            {
                // add to the outgoing page cache the IDs needed...
                Hashtable outgoingData = new Hashtable();
                outgoingData.Add(Keys.ShowAsPopUp, showAsPopUp);
                outgoingData.Add(Keys.ProtocolAccessKey, userAccessLevel);
                outgoingData.Add(Keys.ProtocolIdKey, protocolId);
                outgoingData.Add(Keys.ProtocolProcessIdKey, protocolProcessId);
                pageCachePolicy.Cache(Keys.IncomingDataKey, outgoingData);

                // the object
                currentVersion.UnCache();
                currentVersion.Cache();

                Page.Response.Redirect(
                    Settings.GetKeyValue("SubModuleNavigation.Humans.ProtocolProcessOverviewURL", ""), false);
            }
            catch (Exception ex)
            {
                annunciator.Message = ex.Message;
                done.Enabled = false;
                formsGrid.Enabled = false;
            }
        }

        /// <summary>
        /// Displays an error message on the screen to the user with the exception, and all
        /// inner exception messages.
        /// </summary>
        /// <param name="ex">The exception to report on</param>
        private void DisplayExceptionReport(Exception ex)
        {
            annunciator.Title = AnnunciatorTitle;
            annunciator.Message = ExceptionReport.GetExceptionInfo(ex, false);
        }

        #region Web Form Designer generated code

        /// <summary>
        /// Registers a hidden field used to determine on page load whether to refresh the confirmDelete javascript.
        /// </summary>
        /// <param name="e">arguments to render.</param>
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            ClientScript.RegisterHiddenField(DeleteConfirmationFlag, confirmDelete.ToString());
        }

        /// <summary>
        /// Handler for the event raised when the page is being initialized.
        /// Retrieve the cache policy in force.
        /// </summary>
        /// <param name="e">Arguments assocoiated with the event</param>
        protected override void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);

            cachePolicy = (Policy.ICachePolicy) Session[Policy.Names.CachePolicyKey];
            pageCachePolicy = (Policy.ICachePolicy) Session[Policy.Names.PageCachePolicyKey];
            applicationCachePolicy = (Policy.ICachePolicy) Application[Policy.Names.ApplicationCachePolicyKey];
        }

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.header.Navigate += new System.Web.UI.WebControls.CommandEventHandler(this.OnNavigate);
            this.humansSubModNavigation.Navigate += new PHSRAG.Insight21.InsightWebControls.HumansSubModuleNavigation.NavigateEventHandler(this.OnHumansSubModNavigate);
            this.breadCrumb.Navigate += new System.Web.UI.WebControls.CommandEventHandler(this.OnBreadCrumbNavigate);

            this.formsGrid.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.OnButtonClick);
            this.formsGrid.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.OnItemDataBound);
            this.done.Click += new ImageClickEventHandler(OnDone);
            this.Load += new System.EventHandler(this.OnPageLoad);
        }

        #endregion

        #region Nested type: AddDeleteFormsGridColumnIndex

        /// <summary>
        /// Enumeration of the Grid's column indices
        /// </summary>
        /// 
        private enum AddDeleteFormsGridColumnIndex
        {
            Id,
            QuestionnaireVersionId,
            Name,
            ActionButton,
            Required,
            VersionAllowsMultiple,
            QuestionnaireCategory
        }

        #endregion
    }
}